<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="输入1~100之间的整数" v-model="num" @keydown.enter="guess">
  <button @click="guess">猜</button>
  <h3>{{ result }}</h3>
</template>

<script setup>
import {ref} from "vue";

const num = ref('');
const result = ref('');
let randomNum = parseInt(Math.random() * 100 + 1);
const guess = () => {
  if (num.value > randomNum){
    result.value = '猜大了';
  } else if (num.value < randomNum){
    result.value = '猜小了';
  } else {
    result.value = '恭喜你猜对了';
  }
}
</script>

<style scoped>

</style>